package com.ossjk.qlh.tgb.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.system.annotation.LogModule;
import com.ossjk.core.system.annotation.LogOperation;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.tgb.entity.UserShoppingCart;
import com.ossjk.qlh.tgb.service.IUserShoppingCartService;
import com.ossjk.qlh.tgb.vo.UserShoppingCartDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName UserShoppingCartController
 * @Description 用户购物车接口
 * @Author LZH
 * @Date 2022/1/18 15:44
 */
@RestController
@RequestMapping("/tgb/userShoppingCart")
@Api(tags = "用户购物车")
@LogModule(value = "购物车管理")
public class UserShoppingCartController extends BaseController {

    @Autowired
    private IUserShoppingCartService iUserShoppingCartService;

    @LogOperation("用户购物车列表")
    @ApiOperation(value = "用户购物车列表")
    @RequiresPermissions(value = { "00300030" })
    @GetMapping("/listByUserShoppingCart")
    public ResponseBean listByUserShoppingCart(
            @ApiParam(value = "名字") @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "登录名") @RequestParam(name = "lname", required = false) String lname,
            @ApiParam(value = "手机") @RequestParam(name = "mobile", required = false) String mobile,
            Page page){

        QueryWrapper<UserShoppingCart> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(name)){
            queryWrapper.like("u.name",name);
        }

        if (StrUtil.isNotBlank(lname)){
            queryWrapper.like("u.lname",lname);
        }
        if (StrUtil.isNotBlank(mobile)){
            queryWrapper.eq("u.mobile",mobile);
        }
        queryWrapper.eq("is_pay",0);
        queryWrapper.groupBy("usc.uid");
        Page pageVo = iUserShoppingCartService.getUserShoppingCartList(queryWrapper,page);

        return ResponseBean.Success(pageVo);
    }

    @LogOperation("获取用户购物车详情")
    @ApiOperation(value = "获取用户购物车详情")
    @RequiresPermissions(value = { "003000300005" })
    @GetMapping("/toDetail")
    public ResponseBean<Map<String,Object>> getUserShoppingCartDetail(@ApiParam(value = "用户id") @RequestParam(name = "uid", required = true)String uid){
        Map<String,Object> map = iUserShoppingCartService.getShoppingCartByUid(uid);
        //商品名称，单价，数量，店铺，商家，总价，
        return ResponseBean.Success(map);
    }

}
